﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using LSA.Framework;
using Visuals.Graph;

namespace Visuals.ViewModels
{
    public class WordsGraphViewModel : INotifyPropertyChanged
    {
        #region Data

        private string layoutAlgorithmType;
        private WordsGraph graph;
        private List<String> layoutAlgorithmTypes = new List<string>();

        #endregion

        #region Ctor

        public WordsGraphViewModel(WordInfo mainWord, IEnumerable<WordRelationPair> pairs)
        {
            Graph = new WordsGraph(true);

            Graph.AddVertex(mainWord);
            foreach (WordRelationPair pair in pairs)
            {
                Graph.AddVertex(pair.Word);
                AddNewGraphEdge(mainWord, pair);
            }

            //Add Layout Algorithm Types
            layoutAlgorithmTypes.Add("BoundedFR");
            layoutAlgorithmTypes.Add("Circular");
            layoutAlgorithmTypes.Add("CompoundFDP");
            layoutAlgorithmTypes.Add("EfficientSugiyama");
            layoutAlgorithmTypes.Add("FR");
            layoutAlgorithmTypes.Add("ISOM");
            layoutAlgorithmTypes.Add("KK");
            layoutAlgorithmTypes.Add("LinLog");
            layoutAlgorithmTypes.Add("Tree");

            //Pick a default Layout Algorithm Type
            LayoutAlgorithmType = "LinLog";

        }

        #endregion

        // TODO: finish it
        public void ReLayoutGraph()
        {
            

            NotifyPropertyChanged("Graph");
        }

        #region Private Methods

        private void AddNewGraphEdge(WordInfo from, WordInfo to)
        {
            WordsGraphEdge newEdge = new WordsGraphEdge(from, to);
            Graph.AddEdge(newEdge);
        }

        private void AddNewGraphEdge(WordInfo from, WordRelationPair to)
        {
            WordsGraphEdge newEdge = new WordsGraphEdge(from, to);
            Graph.AddEdge(newEdge);
        }

        #endregion

        #region Public Properties

        public List<String> LayoutAlgorithmTypes
        {
            get { return layoutAlgorithmTypes; }
        }

        public string LayoutAlgorithmType
        {
            get { return layoutAlgorithmType; }
            set
            {
                layoutAlgorithmType = value;
                NotifyPropertyChanged("LayoutAlgorithmType");
            }
        }

        public WordsGraph Graph
        {
            get { return graph; }
            set
            {
                graph = value;
                NotifyPropertyChanged("Graph");
            }
        }

        #endregion

        #region INotifyPropertyChanged Implementation

        public event PropertyChangedEventHandler PropertyChanged;

        private void NotifyPropertyChanged(String info)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(info));
            }
        }

        #endregion
    }
}
